<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/axios.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        a {
            text-decoration: none;
            color: inherit;
        }

        li {
            list-style: none;
        }

        img {
            vertical-align: top;
        }

        #showGoods {
            width: 1226px;
            margin: 0 auto;
            margin-top: 50px;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
        }

        #showGoods li {
            width: 18%;
            box-sizing: border-box;
            padding: 10px;
            font-size: 13px;
            line-height: 20px;
        }

        #showGoods li:hover {
            box-shadow: 0 0 1px 2px rgba(0, 0, 0, 0.2);
        }

        #showGoods li img {
            width: 70%;
            display: block;
            margin: 20px auto;
        }

        #showGoods li .price {
            color: red;
        }

        #showGoods li .name {
            /* 多行文本溢出隐藏 */
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <div id="page">
        <ul id="showGoods" >
            <li v-for="goods in list" :key="goods.goodsId">
                <a href="">
                    <img :src="goods.goodsImg" alt="">
                    <div class="price">{{goods.goodsPrice}}</div>
                    <div class="name">{{goods.goodsName}}</div>
                </a>
            </li>
        </ul>
    </div>

</body>
<script>

    var vm = new Vue({
        el: "#page",
        data: {
            list: [],
        },
        methods: {
            getData() {
                axios({
                    method: "get",
                    url: "../data/data.json",
                }).then(res => {
                    return res.data;  // 后续的then,可以用形参接收当前返回值
                }).then(data => {
                    console.log("请求得到的数据", data);
                    this.list = data;
                })
            }
        },
        mounted() {
            this.getData();
        },
    })








</script>

</html>